package com.classic.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.classic.content.contents;
import com.classic.duanzhi.R;
import com.jaeger.library.StatusBarUtil;

import java.util.Calendar;

public abstract class BaseActivity extends AppCompatActivity implements View.OnClickListener {
    protected abstract int getLayoutId();

    protected abstract void initView();

    protected abstract void initData();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        initBack();
        initView();
        setImmerseLayout();
        initData();
    }

    public TextView mTitle;

    //实例化title
    private void initBack() {
        TextView id = findViewById(R.id.iv_title_back);
        mTitle = findViewById(R.id.tv_title_appname);
        if (null != id) {
            id.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            mTitle.setText(getActivityTitle());
            mTitle.setTextColor(getResources().getColor(contents.titleColor));
            id.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(contents.IC_BACK), null, null, null);
        }
    }

    private void initTitleColor() {
        View id = findViewById(R.id.ll_title_layout);
        if (null != id) id.setBackgroundColor(getResources().getColor(contents.TITLE_BACKGROUND));
    }

    public void invaliTitle(String title){
        if (null!=mTitle)mTitle.setText(title);
    }
    public abstract String getActivityTitle();

    protected void setImmerseLayout() {// view为标题栏
        StatusBarUtil.setColor(this, getResources().getColor(contents.TITLE_BACKGROUND), 0);
        initTitleColor();
    }

    public int getStatusBarHeight(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",
                "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }


    protected void showTT(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }


    @Override
    protected void onStart() {
        super.onStart();
    }

    public static final int MIN_CLICK_DELAY_TIME = 1000;
    private long lastClickTime = 0;

    @Override
    public void onClick(View v) {
        long currentTime = Calendar.getInstance().getTimeInMillis();
        if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime;
            onNoDoubleClick(v);
        }
    }

    public void onNoDoubleClick(View v) {

    }

}